//#define __DEBUG__
#define THIS_FILE "fn_createmines.sqf"
#include "x_setup.sqf"

if !(call FUNC(checkSHC)) exitWith { 0 };
if (isNil QGVAR(LandMines)) exitWith { 0 };

private ["_radius", "_pos", "_road", "_roads", "_mines", "_i", "_dir", "_type", "_pos_center", "_do_patrol", "_ret_grps","_cnt_defend","_homed"];
__TRACE_1("","_this")

PARAMS_2(_pos,_radius);

_roads = (_pos nearRoads _radius);
_mines = ((floor(count _roads / 10) min 10) min (count _roads));
if (count _roads > 0) then {
	for "_i" from 0 to _mines do {
		_road = _roads call FUNC(randomArrayVal);
		_dir = random(360);
		if (count (roadsConnectedTo _road) > 0) then { _dir = [_road, (roadsConnectedTo _road) call FUNC(randomArrayVal)] call FUNC(DirTo); };
		_roads = _roads - [_road];
		_pos =  getPosATL _road;
		_type = GVAR(LandMines) call FUNC(randomArrayVal);
		_mine = createMine [_type, _pos, [], 0];
		_mine setdir _dir;
		_mine setPosATL [getposatl _mine select 0,getposatl _mine select 1,0];
		GVAR(side_enemy) revealMine _mine;
		GVAR(mines_created) set [count GVAR(mines_created), _mine];
		
#ifdef __DEBUG__
		[format["mines_%1",_mine], getPosASL _mine,"ICON","ColorOrange",[0.5,0.5],"",0,"n_mortar"] call FUNC(CreateMarkerGlobal);
#endif
	};
};
_mines